package singleton.myself;


import singleton.myself.seriable.SeriableSingleton;

import java.io.*;

/**
 * Created by Tom.
 */
public class SeriableSingletonTest {
    public static void main(String[] args) {

//        SeriableSingleton s1 = null;
//        SeriableSingleton s2 = SeriableSingleton.getInstance();
//
//        FileOutputStream fos = null;
//        try {
//
//            fos = new FileOutputStream("SeriableSingleton.obj");
//            ObjectOutputStream oos = new ObjectOutputStream(fos);
//            oos.writeObject(s2);
//            oos.flush();
//            oos.close();
//
//            FileInputStream fis = new FileInputStream("SeriableSingleton.obj");
//            ObjectInputStream ois = new ObjectInputStream(fis);
//            s1 = (SeriableSingleton)ois.readObject();
//            ois.close();
//
//            System.out.println(s1);
//            System.out.println(s2);
//            System.out.println(s1 == s2);
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        SeriableSingleton s1 =SeriableSingleton.getInstance();

        try {
            FileOutputStream fos=new FileOutputStream("seriable.obj");
            ObjectOutputStream oos=new ObjectOutputStream(fos);
            oos.writeObject(s1);

            FileInputStream fis=new FileInputStream("seriable.obj");
            ObjectInputStream ois= new ObjectInputStream(fis);

            SeriableSingleton s2= (SeriableSingleton) ois.readObject();
            System.out.println(s1==s2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
